package com.example.finalproject.experiments.intent

import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.widget.Button
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.finalproject.R

class IntentExperimentActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_intent_experiment)

        val btnToSecond = findViewById<Button>(R.id.btnToSecond)
        val btnSendSms = findViewById<Button>(R.id.btnSendSms)
        val tvResult = findViewById<TextView>(R.id.tvResult)

        btnToSecond.setOnClickListener {
            val intent = Intent(this, SecondActivity::class.java)
            intent.putExtra("extra_data", "我是传递的信息")
            startActivityForResult(intent, 1)
        }

        btnSendSms.setOnClickListener {
            val intent = Intent(Intent.ACTION_SENDTO)
            intent.data = Uri.parse("smsto:10086") // 可替换为目标号码
            intent.putExtra("sms_body", "测试短信内容")
            startActivity(intent)
        }
    }

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)
        if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
            val result = data?.getStringExtra("result_data")
            findViewById<TextView>(R.id.tvResult).text = result
        }
    }
}